package smartlifev30.com.sdk.api.service_app;

import android.support.annotation.NonNull;

import smartlifev30.com.sdk.util.JsonUtil;
import smartlifev30.com.sdk.api.CallBack;
import smartlifev30.com.sdk.bean.request.GetEmailRequest;
import smartlifev30.com.sdk.bean.request.GetPushConfigRequest;
import smartlifev30.com.sdk.bean.request.GetSmsBalanceRequest;
import smartlifev30.com.sdk.bean.request.JPushRegIdUploadRequest;
import smartlifev30.com.sdk.bean.request.SetEmailRequest;
import smartlifev30.com.sdk.bean.request.SetPushConfigRequest;
import smartlifev30.com.sdk.bean.response.LoginResponse;
import smartlifev30.com.sdk.net.baiwei.NetManager;
import smartlifev30.com.sdk.net.baiwei.ResponseHelper;

/**
 * Created by tys on 2018/8/13.
 */

public class MessagePushImpl implements IMessagePush {


    @Override
    public void jPushRegIdUpload(@NonNull String userName, @NonNull String token, @NonNull String jPushRegId, @NonNull String channelID, @NonNull CallBack<LoginResponse> callBack) {
        JPushRegIdUploadRequest jpushRegIdUploadRequest = new JPushRegIdUploadRequest();
        jpushRegIdUploadRequest.setFrom(userName);
        jpushRegIdUploadRequest.setMsg_id(callBack.getMsgId());
        jpushRegIdUploadRequest.setMsg_class("app_auth");
        jpushRegIdUploadRequest.setMsg_name("jpush_regid_upload");
        jpushRegIdUploadRequest.setToken(token);
        jpushRegIdUploadRequest.setUser(jpushRegIdUploadRequest.new User(jPushRegId, channelID));
        NetManager.getInstance().sendMessage(JsonUtil.toString(jpushRegIdUploadRequest));
        ResponseHelper.addListen(callBack);
    }

    @Override
    public void getPushConfig(@NonNull String userName, @NonNull String token, @NonNull String type, @NonNull CallBack<LoginResponse> callBack) {
        GetPushConfigRequest getPushConfigRequest = new GetPushConfigRequest();
        getPushConfigRequest.setFrom(userName);
        getPushConfigRequest.setMsg_id(callBack.getMsgId());
        getPushConfigRequest.setMsg_class("msg_mgmt");
        getPushConfigRequest.setMsg_name("msgpush_getconfig");
        getPushConfigRequest.setMsg_type("get");
        getPushConfigRequest.setToken(token);
        getPushConfigRequest.setConfig(getPushConfigRequest.new Config(type));
        NetManager.getInstance().sendMessage(JsonUtil.toString(getPushConfigRequest));
        ResponseHelper.addListen(callBack);
    }

    @Override
    public void setPushConfig(@NonNull String userName, @NonNull String token, @NonNull String type, @NonNull Integer app, @NonNull Integer sms, @NonNull Integer wechat, @NonNull Integer email, @NonNull CallBack<LoginResponse> callBack) {
        SetPushConfigRequest setPushConfigRequest = new SetPushConfigRequest();
        setPushConfigRequest.setFrom(userName);
        setPushConfigRequest.setMsg_id(callBack.getMsgId());
        setPushConfigRequest.setMsg_class("msg_mgmt");
        setPushConfigRequest.setMsg_name("msgpush_setconfig");
        setPushConfigRequest.setMsg_type("set");
        SetPushConfigRequest.Config config = setPushConfigRequest.new Config();
        config.setType(type);
        config.setApp(app);
        config.setSms(sms);
        config.setWechat(wechat);
        config.setEmail(email);
        setPushConfigRequest.setConfig(config);
        NetManager.getInstance().sendMessage(JsonUtil.toString(setPushConfigRequest));
        ResponseHelper.addListen(callBack);
    }

    @Override
    public void getSmsBalance(@NonNull String userName, @NonNull String token, @NonNull String sn, @NonNull CallBack<LoginResponse> callBack) {
        GetSmsBalanceRequest getSmsBalanceRequest = new GetSmsBalanceRequest();
        getSmsBalanceRequest.setFrom(userName);
        getSmsBalanceRequest.setMsg_id(callBack.getMsgId());
        getSmsBalanceRequest.setMsg_class("msg_mgmt");
        getSmsBalanceRequest.setMsg_name("msgpush_getsmsbalance");
        getSmsBalanceRequest.setMsg_type("get");
        getSmsBalanceRequest.setConfig(getSmsBalanceRequest.new Config(sn));
        NetManager.getInstance().sendMessage(JsonUtil.toString(getSmsBalanceRequest));
        ResponseHelper.addListen(callBack);
    }

    @Override
    public void getEmail(@NonNull String userName, @NonNull String token, @NonNull CallBack<LoginResponse> callBack) {
        GetEmailRequest getEmailRequest = new GetEmailRequest();
        getEmailRequest.setFrom(userName);
        getEmailRequest.setMsg_id(callBack.getMsgId());
        getEmailRequest.setMsg_class("msg_mgmt");
        getEmailRequest.setMsg_name("get_email");
        getEmailRequest.setToken(token);
        NetManager.getInstance().sendMessage(JsonUtil.toString(getEmailRequest));
        ResponseHelper.addListen(callBack);
    }

    @Override
    public void setEmail(@NonNull String userName, @NonNull String token, @NonNull String email, @NonNull CallBack<LoginResponse> callBack) {
        SetEmailRequest setEmailRequest = new SetEmailRequest();
        setEmailRequest.setFrom(userName);
        setEmailRequest.setMsg_id(callBack.getMsgId());
        setEmailRequest.setMsg_class("msg_mgmt");
        setEmailRequest.setMsg_name("set_mail");
        setEmailRequest.setToken(token);
        setEmailRequest.setUser(setEmailRequest.new User(email));
        NetManager.getInstance().sendMessage(JsonUtil.toString(setEmailRequest));
        ResponseHelper.addListen(callBack);
    }


}
